package test;

import static org.junit.Assert.*;

import movement.Location;

import org.junit.Before;
import org.junit.Test;

import dispatch.DispatchCenter;
import emergency.*;
import emergency.Fire.Size;

public class testState {

	Emergency fire, robbery, trafficaccident, publicdisturbance;
	DispatchCenter center;


	@Before
	public void setUp() throws Exception {
		center = new DispatchCenter("DC 1", new Location(45, 45,
				"DC 1 - Location"), new Location(60, 60, "GarageLocation"));
		fire = new Fire(new Location(10, 10, "Foch"), Severity.BENIGN, center,
				Size.LOCAL, true, 5, 5);
		robbery = new Robbery(new Location(20, 20, "Brussel"), Severity.URGENT,
				center, true, true);
		trafficaccident = new TrafficAccident(new Location(15, 15, "Leuven"),
				Severity.NORMAL, center, 3, 1);
		publicdisturbance = new PublicDisturbance(new Location(15, 18,
				"Naamsestraat"), Severity.SERIOUS, center, 3);
	}

	@Test(expected = IllegalStateException.class)
	public void testCancelCancel() throws Exception {
		fire.sendUnits();
		fire.cancelEmergency();
		fire.cancelEmergency();
	}

	@Test(expected = IllegalStateException.class)
	public void testCancelComplete() throws Exception {
		fire.sendUnits();
		fire.cancelEmergency();
		fire.complete();
	}

	
	@Test(expected = IllegalStateException.class)
	public void testCancelSendUnits() throws Exception {
		fire.sendUnits();
		fire.cancelEmergency();
		fire.sendUnits();
	}

	@Test(expected = IllegalStateException.class)
	public void testCompletedCancel() throws Exception {
		fire.sendUnits();
		fire.complete();
		fire.cancelEmergency();
	}

	@Test(expected = IllegalStateException.class)
	public void testCompletedComplete() throws Exception {
		fire.sendUnits();
		fire.complete();
		fire.complete();
	}

	@Test(expected = IllegalStateException.class)
	public void testCompletedSendUnits() throws Exception {
		fire.sendUnits();
		fire.complete();
		fire.sendUnits();
	}

	@Test(expected = IllegalStateException.class)
	public void testInProgressSendUnits() throws Exception {
		fire.sendUnits(); // going to InProgress
		fire.sendUnits();
	}

	@Test(expected = IllegalStateException.class)
	public void testRecordedComplete() throws Exception {
		fire.complete();
	}

	@Test
	public void testValidStates() throws Exception {
		
		assertEquals(robbery.getStateName(), "staterecorded");
		assertEquals(trafficaccident.getStateName().toString(),
				"staterecorded");
		assertEquals(publicdisturbance.getStateName().toString(),
				"staterecorded");
		robbery.sendUnits();
		trafficaccident.sendUnits();
		publicdisturbance.cancelEmergency();
		assertEquals(robbery.getStateName().toString(), "stateinprogress");
		assertEquals(trafficaccident.getStateName().toString(),
				"stateinprogress");
		assertEquals(publicdisturbance.getStateName().toString(),
				"statecanceled");
		robbery.complete();
		trafficaccident.cancelEmergency();
		assertEquals(robbery.getStateName().toString(), "statecompleted");
		assertEquals(trafficaccident.getStateName().toString(),
				"statecanceled");
	}
}
